import java.util.HashMap;

public class t20 {
    //有效的括号
    public static void main(String[] args) {
        String s = "[({(())}[()])]";
        System.out.println(isValid(s));
    }

    public static boolean isValid(String s) {
        if(s.length()%2==1){
            return false;
        }
        HashMap<Character, Integer> map = new HashMap<>();
        map.put('(', 0);
        map.put(')', 1);
        map.put('[', 3);
        map.put(']', 4);
        map.put('{', 6);
        map.put('}', 7);
        int a = 0;
        while (s.length()!=0) {
            if (map.get(s.charAt(a)) + 1 == map.get(s.charAt(s.length() - 1 - a))) {
                s = s.substring(a + 1, s.length() - a - 1);
                a = 0;
                System.out.println(s);
            } else if (map.get(s.charAt(a)) + 1 == map.get(s.charAt(a + 1))) {
                s = s.substring(a + 2, s.length());
                a = 0;
                System.out.println(s);
            } else if (map.get(s.charAt(s.length() - 2 - a)) + 1 == map.get(s.charAt(s.length() - 1 - a))) {
                s = s.substring(a, s.length() - 2);
                System.out.println(s);
                a = 0;
            }else {
                return false;
            }
        }
        return true;
    }
}
